<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<meta name="description" content="Mailbox with some customizations as described in docs" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<%@ include file="/include/main_include.jsp"%>
</head>
<body>
	<div class="grsun-toolbar">
		<button type="button" id="add" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
			<i class="ace-icon fa fa-plus blue bigger"></i>
			增加
		</button>
		<button type="button" id="edit" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
			<i class="ace-icon fa fa-edit orange bigger"></i>
			修改
		</button>
		<button type="button" id="del" class="btn btn btn-toolbar btn-white btn-info no-border auth-hidden">
			<i class="ace-icon fa fa-remove red bigger"></i>
			删除
		</button>
	</div>
	<table id="menu_list_table"></table>  
	<script type="text/javascript">
		$(function(){
			$('#add').on('click', function() {
				add();
			});

			$('#edit').on('click', function() {
				edit();
			});
			
			$('#del').on('click', function() {
				del();
			});
			
			$('#refresh').on('click', function() {
				menuListTable.treegrid('reload');
			});
		});
		var menuListTable = $('#menu_list_table').treegrid({  
			fitColumns: true,
			fit:true,
			nowrap:true,
			animate:true,
			nowrap: true,
		    url:'${path}/sysDictionaries/listByParent.do',
		    idField:'id',    
		    treeField:'text',    
		    columns:[[    
		        {title:'菜单名称',field:'text',width:'10%'},    
		        {title:'编码',field:'dicCode',width:'10%'},    
		        {title:'排序',field:'sort',width:'10%'}  
		    ]]    
		});  
		function add(){
			var MENU_ID = '';
			openedit(MENU_ID);
		}
		function edit(){
			var node = menuListTable.treegrid('getSelected');
			if (node) {
				var MENU_ID = '';
				if(node){
					MENU_ID = node.id;
				}
				openedit(MENU_ID);
			} else {
				layer.msg('请选择一条数据！', {
					time : 1000
				})
			}
		}
		function openedit(MENU_ID){
			layer.open({
				title : '信息',
				type : 2,
				btn : ['保存','关闭'],
				yes : function(index,layero) {
					var iframeWin = window[layero.find('iframe')[0]['name']];
					iframeWin.$("#menuform").submit();
				},
				btn2 : function(index, layero) {
				},
				area : [ '800px', '330px' ],
				content : rootpath + '/sysDictionaries/toEdit.do?dictionariesId='+MENU_ID
			});
		}
		function del() {
			var node = menuListTable.treegrid('getSelected');
			if (node) {
				layer.confirm('您确定要删除吗？', {
					btn : [ '确定', '取消' ]
				}, function() {
					$.uitools.showLoading();//打开处理中遮罩层
					$.ajax({
						cache : true,
						type : "POST",
						url : rootpath + '/sysDictionaries/delete.do',
						data : {
							dictionariesId : node.id
						},
						async : false,
						error : function(request) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							layer.msg('系统异常！', {
								icon : 2,
								time : 1000
							})
						},
						success : function(data) {
							$.uitools.hideLoading();//关闭处理中遮罩层
							if (data.code==0){
								layer.msg('删除成功！', {
									icon : 1,
									time : 1000
								}, function() {
									menuListTable.treegrid('reload');
								})
							}else {
								layer.msg('删除异常！', {
									icon : 2,
									time : 1000
								})
							}
						}
					});
				}, function() {
				});
			} else {
				layer.msg('请选择一条数据！', {
					time : 1000
				})
			}
		}
	</script>
</body>
</html>
